﻿using BW.MesProject.Equipment.Domain.Equipment;
using BW.MesProject.Equipment.Infrastructure.Dto.Input.DeviceLedger;
using BW.MesProject.Equipment.Infrastructure.Dto.Output.DeviceLedger;
using BW.MesProject.Equipment.Infrastructure.Equipment;
using BW.MesProject.Public.ErrorCode;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BW.MesProject.Equipment.Host.Controllers
{
    /// <summary>
    /// 设备台账控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeviceLedgerController : ControllerBase
    {
        private readonly IDeviceLedgerService _deviceLedgerService;
        /// <summary>
        /// 构造函数，注入设备台账服务
        /// </summary>
        /// <param name="deviceLedgerService"></param>
        public DeviceLedgerController(IDeviceLedgerService deviceLedgerService)
        {
            this._deviceLedgerService = deviceLedgerService;
        }

        /// <summary>
        /// 获取设备类型信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<List<DeviceTypeModel>> GetDeviceTypeValue()
        {
            return _deviceLedgerService.GetDeviceTypeValue();
        }

        /// <summary>
        /// 添加设备台账接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> AddDeviceLedger([FromBody]AddDeviceLedgerInput input)
        {
            return _deviceLedgerService.AddDeviceLedger(input);
        }

        /// <summary>
        /// 获取设备台账列表  
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiPaging<DeviceLedgerOutput> GetDeviceLedgerList([FromQuery]DeviceLedgerQueryInput input)
        {
            return _deviceLedgerService.GetDeviceLedgerList(input);
        }

        /// <summary>
        /// 根据设备台账获取设备台账数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<DeviceLedgerOutput> GetDeviceLedgerValue([FromQuery]long id)
        {
            return _deviceLedgerService.GetDeviceLedgerValue(id);
        }

        /// <summary>
        /// 修改设备台账
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> UpdateDeviceLedger(UpdateDeviceLedgerInput input)
        {
            return _deviceLedgerService.UpdateDeviceLedger(input);
        }

        /// <summary>
        /// 删除设备台账
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public ApiResult<int> DeleteDeviceLedger([FromQuery]long id)
        {
            return _deviceLedgerService.DeleteDeviceLedger(id);
        }
    }
}
